package com.budwk.app.util.poiUtils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.StrFormatter;
import com.budwk.app.sqfw.dto.FireHiddenCheckWordDTO;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;

import java.io.ByteArrayOutputStream;
import java.util.Date;
import java.util.Map;

import static com.budwk.app.util.poiUtils.CommonFormOfficeUtils.generateWordDocument;

/**
 * @author ZY.Wang
 * @since 2023/8/3
 */
public class RecNoticeOfficeUtils {

    public static ByteArrayOutputStream createRecNoticeOfficeUtils(FireHiddenCheckWordDTO wordDTO) {
        if (StringUtils.isBlank(wordDTO.getA23()) || wordDTO.getA23().equals("否")) return null;

        long startTime = System.currentTimeMillis();
        Map<String, Object> paramMap = Maps.newHashMap();

        paramMap.put("unitName", "      " + wordDTO.getUnitName() + "      ");
        paramMap.put("a3", "      " + wordDTO.getA3() + "      ");
        paramMap.put("a13", wordDTO.getA13());

        if (StringUtils.isBlank(wordDTO.getA14())) {
            paramMap.put("textFlag", false);
        } else {
            paramMap.put("textFlag", true);
            String a15 = wordDTO.getA15();
            if (StringUtils.isBlank(a15)) a15 = "";

            String a16 = wordDTO.getA16();

            if (StringUtils.isBlank(a15) && StringUtils.isBlank(a16)) {
                paramMap.put("textFlag", false);
            }
            String text = StrFormatter.format("已电话告知产权单位负责人：{}，其负责人电话为：{}。", a15, a16);
            paramMap.put("text", text);
        }

        Date fillDate = wordDTO.getFillDate();
        if(fillDate == null) fillDate = wordDTO.getCreateDate();

        String fillDateYear = DateUtil.year(fillDate) + "";
        String fillDateMonth = DateUtil.month(fillDate) + 1 + "";
        String fillDateDay = DateUtil.dayOfMonth(fillDate) + "";
        paramMap.put("fillDateYear", fillDateYear);
        paramMap.put("fillDateMonth", fillDateMonth);
        paramMap.put("fillDateDay", fillDateDay);

        return generateWordDocument(paramMap, "recNotic.docx", "安全隐患通知书", startTime);
    }
}
